<?php
include('logic/config.php');


//Connect to server and select database.
mysql_connect($db_server,$db_user,$db_pass)or die("cannot connect to server");
mysql_select_db($db_database)or die("cannot select DB");


// Passkey that got from link
$passkey=$_GET['a'];

$tbl_name="user_info";

// Retrieve data from table where row that match this passkey
$sql1="SELECT * FROM $tbl_name WHERE confirm_code ='$passkey' and status='0'";
$result1=mysql_query($sql1);

// If successfully queried
if($result1)
{

		// Count how many row has this passkey
		$count=mysql_num_rows($result1);
		
		// if found this passkey in our database, retrieve data from table "temp_members_db"
		if($count==1)
		{
		
			$rows=mysql_fetch_array($result1);
			$status=$rows['status'];
			$user_id=$rows['user_id'];
			
			// update user_info table, change status to 1
			$sql3 = "update $tbl_name SET status='1' where confirm_code='$passkey'" ;
			
			$result2=mysql_query($sql3);
			
			
			$tbl_name = "user_credit";
			
			$sql3 = "INSERT INTO $tbl_name (user_id,credit_amount) Values ('$user_id','0') " ;
			
			$result2=mysql_query($sql3);
			
			
			
			header('Location: account-verification.php');
	
			}
		}

		// if not found passkey, display message "Wrong Confirmation code"
		else 
		{
		echo "The verification link has expired";
		//header('Location: link-expired.php');
		}

?>